package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Alltickets;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.IAllticketsService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("alltickets")
public class AllticketsController {

    @Autowired
    private IAllticketsService allticketsService;
    @Autowired
    private IUserService userService;

    //购票
    @PostMapping("save")
    public JSONResult saveAlltickets(Alltickets alltickets) {
        JSONResult json = new JSONResult();
        try {
            allticketsService.save(alltickets);
        } catch (Exception e) {
            json.mark(e.getMessage());
            e.printStackTrace();
        }
        User u = userService.selectByUserId(alltickets.getUser().getId());
        json.setResult(u);
        return json;
    }
}
